package com.estronger.shopmanage.adapter.tasking;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.bean.DesignerTrip;
import com.estronger.shopmanage.utils.ConvertUtils;

import java.util.ArrayList;

/**
 * Created by Soonfor on 2017/6/6.
 */

public class DesignertripDetailAdapter extends BaseAdapter {

    private ArrayList<DesignerTrip.customer> mList;
    Context mContext;

    public DesignertripDetailAdapter(Context context, ArrayList<DesignerTrip.customer> lt) {
        mContext = context;
        mList = lt;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if(mList != null)
            return mList.size();
        else
            return 0;
    }

    @Override
    public DesignerTrip.customer getItem(int position) {
        // TODO Auto-generated method stub
        if(mList == null || mList.size() <=0)
            return null;
        else
            return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final ListItemView ltv;
        DesignerTrip.customer customer = mList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.adpter_delivertripdetail, null);
            ltv = new ListItemView();
            ltv.targetname = (TextView) convertView
                    .findViewById(R.id.targetname);
            ltv.yytime_tt = (TextView)convertView.findViewById(R.id.yytime_tt);
            ltv.deliveradr = (TextView) convertView.findViewById(R.id.deliveradr);

            convertView.setTag(ltv);
        } else {
            ltv = (ListItemView) convertView.getTag();
        }

        try {
            ltv.targetname.setText(ConvertUtils.formatNullF(customer.cstbuildname) + ConvertUtils.formatNull(mList.get(position).cstname));
            String planDate = customer.planmeasuredate+"";
            if(planDate != null && !planDate.equals("") && planDate.contains(" ")){
                planDate = planDate.substring(planDate.indexOf(" ")+1,planDate.length());
            }
            ltv.yytime_tt.setText(planDate);
            ltv.deliveradr.setText(ConvertUtils.formatNull(mList.get(position).address));

        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    class ListItemView {
        TextView targetname;
        TextView yytime_tt;
        TextView deliveradr;
    }
}